﻿using System.Collections.Generic;
using System.Web.Mvc;
using Kwd.Summary.Services;
using Orchard.Logging;

namespace Kwd.Summary.ViewModels
{
  /// <summary>
  /// Helper to create a view on the list of strategy options.
  /// </summary>
  public class StrategyOptions
  {
    private ILogger _logger;

    public StrategyOptions(ILogger logger)
    {
      _logger = logger ?? NullLogger.Instance;
    }

    public StrategyOptions()
      : this(null)
    { }

    public IEnumerable<SelectListItem> Build(IEnumerable<ISummaryStrategy> strategies, string currentSelectedStrategy)
    {
      //currently not flexable enough to handle anything but strategies from this module :(
      foreach (var item in strategies)
      {
        bool isSelected = item.GetType().Name == currentSelectedStrategy;
        if (item is DefaultSummary)
          yield return new SelectListItem()
          {
            Text = "Default",
            Value = typeof(DefaultSummary).Name,
            Selected = isSelected
          };

        else if (item is FirstParagraphSummary)
          yield return new SelectListItem()
          {
            Text = "First Paragraph",
            Value = typeof(FirstParagraphSummary).Name,
            Selected = isSelected
          };

        else if (item is ExplicitSummary)
          yield return new SelectListItem()
          {
            Text = "Explicit Text",
            Value = typeof(ExplicitSummary).Name,
            Selected = isSelected
          };
        else
        {
          _logger.Warning("Dropping summary strategy option: {0}", item.GetType().Name);
        }
      } 
    }
  }
}